package cn.vpclub.shcmcc.web;

import cn.vpclub.shcmcc.entity.Employee;
import cn.vpclub.shcmcc.mapper.EmployeeMapper;
import cn.vpclub.shcmcc.params.Emp;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author LiLeLe
 * @Date 2020/6/8 16:42
 **/
@RequestMapping(value = "supportManager")
@RestController
public class SupportManagerController {
    @Autowired
    EmployeeMapper employeeMapper;

    @RequestMapping(value = "addEmployee", method = RequestMethod.POST)
    public void addEmployee(@RequestBody Emp emp) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("mobile", emp.getMobile());
        List<Employee> list = employeeMapper.selectList(queryWrapper);
        if (list.size() == 0) {
            Employee employee = new Employee();
            employee.setMobile(emp.getMobile());
            employee.setDepartment(emp.getDepartment());
            employee.setName(emp.getName());
            employee.setUserType(emp.getUserType());
            employee.setCreatedBy(new Long(1458794));
            employee.setCreatedTime(System.currentTimeMillis());
            employee.setDeleted(1);
            employee.setFollow(1);
            employeeMapper.insert(employee);
        } else {
            Employee employee1 = new Employee();
            employee1.setUserType(list.get(0).getUserType() + ',' + emp.getUserType());
            UpdateWrapper updateWrapper = new UpdateWrapper();
            updateWrapper.eq("mobile", emp.getMobile());
            employeeMapper.update(employee1, updateWrapper);
        }
    }

    @RequestMapping(value = "queryEmployee")
    public List queryEmployee() {
        List list = employeeMapper.selectList(null);
        return list;
    }
}
